package com.loong.life.business;

import com.loong.common.mybatis.business.AbstractBusiness;
import com.loong.life.common.backend.param.AgentQueryParam;
import com.loong.life.model.AgentInformation;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Description:
 * @Author: 刘群
 * @Date: 2020/11/26 16:31
 */
@Repository
public class AgentInformationBusiness extends AbstractBusiness<AgentInformation> {

    /**
     * 根据查询参数查询代理商
     * @param param 查询参数
     * @return 代理商集合
     */
    public List<AgentInformation> findAgentByParam(AgentQueryParam param){
        Condition condition = new Condition(AgentInformation.class);
        Example.Criteria criteria = condition.createCriteria();
        if (ObjectUtils.isNotEmpty(param.getAgentName())){
            criteria.andLike("agentName","%"+param.getAgentName()+"%");
        }
        if (ObjectUtils.isNotEmpty(param.getStatus())){
            criteria.andEqualTo("status",param.getStatus());
        }
        if (ObjectUtils.isNotEmpty(param.getAddress())){
            criteria.andLike("address","%"+param.getAddress()+"%");
        }
        return findByCondition(condition);
    }

    /**
     * 根据代理商名称查询代理商
     * @param agentName 代理商名称
     * @return 代理商集合
     */
    public List<AgentInformation> findAgentByAgentName(String agentName) {
        Condition condition = new Condition(AgentInformation.class);
        Example.Criteria criteria = condition.createCriteria();
        if (StringUtils.isEmpty(agentName)) return null;
        criteria.andEqualTo("agentName", agentName);
        return findByCondition(condition);
    }

}
